home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / PHPUnit / RepeatedTest.php < prev    next >
PHP Script  |  2004-10-01  |  3KB  |  113 lines

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: PHPUnit                                                        |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2003 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  7. // +------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,        |
  9. // | that is available at http://www.php.net/license/3_0.txt.               |
  10. // | If you did not receive a copy of the PHP license and are unable to     |
  11. // | obtain it through the world-wide-web, please send a note to            |
  12. // | license@php.net so we can mail you a copy immediately.                 |
  13. // +------------------------------------------------------------------------+
  14. //
  15. // $Id: RepeatedTest.php,v 1.8 2004/06/10 06:47:51 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit/TestDecorator.php';
  19.  
  20. /**
  21.  * A Decorator that runs a test repeatedly.
  22.  *
  23.  * Here is an example:
  24.  *
  25.  * <code>
  26.  * <?php
  27.  * require_once 'PHPUnit.php';
  28.  * require_once 'PHPUnit/RepeatedTest.php';
  29.  *
  30.  * class MathTest extends PHPUnit_TestCase {
  31.  *     var $fValue1;
  32.  *     var $fValue2;
  33.  *
  34.  *     function MathTest($name) {
  35.  *         $this->PHPUnit_TestCase($name);
  36.  *     }
  37.  *
  38.  *     function setUp() {
  39.  *         $this->fValue1 = 2;
  40.  *         $this->fValue2 = 3;
  41.  *     }
  42.  *
  43.  *     function testAdd() {
  44.  *         $this->assertTrue($this->fValue1 + $this->fValue2 == 5);
  45.  *     }
  46.  * }
  47.  *
  48.  * $suite = new PHPUnit_TestSuite;
  49.  *
  50.  * $suite->addTest(
  51.  *   new PHPUnit_RepeatedTest(
  52.  *     new MathTest('testAdd'),
  53.  *     10
  54.  *   )
  55.  * );
  56.  *
  57.  * $result = PHPUnit::run($suite);
  58.  * print $result->toString();
  59.  * ?>
  60.  * </code>
  61.  *
  62.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  63.  * @copyright   Copyright © 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>
  64.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  65.  * @category    PHP
  66.  * @package     PHPUnit
  67.  */
  68. class PHPUnit_RepeatedTest extends PHPUnit_TestDecorator {
  69.     /**
  70.     * @var    integer
  71.     * @access private
  72.     */
  73.     var $_timesRepeat = 1;
  74.  
  75.     /**
  76.     * Constructor.
  77.     *
  78.     * @param  object
  79.     * @param  integer
  80.     * @access public
  81.     */
  82.     function PHPUnit_RepeatedTest(&$test, $timesRepeat = 1) {
  83.         $this->PHPUnit_TestDecorator($test);
  84.         $this->_timesRepeat = $timesRepeat;
  85.     }
  86.  
  87.     /**
  88.     * Counts the number of test cases that
  89.     * will be run by this test.
  90.     *
  91.     * @return integer
  92.     * @access public
  93.     */
  94.     function countTestCases() {
  95.         return $this->_timesRepeat * $this->_test->countTestCases();
  96.     }
  97.  
  98.     /**
  99.     * Runs the decorated test and collects the
  100.     * result in a TestResult.
  101.     *
  102.     * @param  object
  103.     * @access public
  104.     * @abstract
  105.     */
  106.     function run(&$result) {
  107.         for ($i = 0; $i < $this->_timesRepeat; $i++) {
  108.             $this->_test->run($result);
  109.         }
  110.     }
  111. }
  112. ?>
  113.